package br.com.pd.messaging;

import br.com.pd.invocation.Invoker;
import br.com.pd.invocation.InvokerIF;
import br.com.util.PropertiesLoader;

public class ManagerRequestHandle implements Listener {

	private int port;
	private RequestReceiver requestReceiver;
	private RequestSender requestSender;
	private InvokerIF invoker;
	
	
	public ManagerRequestHandle(){
		this.port = Integer.parseInt(PropertiesLoader.getInstance().getPropertie(PropertiesLoader.PORT_LOCATION_REMOTE_OBJECT));
		this.invoker = new Invoker(this);
		this.requestSender = new RequestSender();
		this.requestReceiver = new RequestReceiver(this.port);
		this.requestReceiver.addObserver(this);
		this.requestReceiver.start();
		this.requestSender.start();
		
	}

	
	public void send(String b, String location, int port){
		this.requestSender.send(b, location, port);
	}
	
	@Override
	public void update() {
		this.invoker.execute(this.requestReceiver.receive());
	}
	
	
	public static void main(String[] args) {
		ManagerRequestHandle m = new ManagerRequestHandle();
	}

}
